﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IDAL;
using DataMode;

namespace DAL
{
    class AdminVideo : IAdminVideo
    {
        DataModeDataContext ctx = new DataModeDataContext();

        public IOrderedQueryable GetOnePageVideo(int page)
        {
            return (IOrderedQueryable)((from v in ctx.video
                                        orderby v.username
                                        select v).Skip(6 * (page - 1)).Take(6));
        }

        public IOrderedQueryable GetOnePageVideoByTime(int page)
        {
            return (IOrderedQueryable)((from v in ctx.video
                                        orderby v.load_time
                                        select v).Skip(6 * (page - 1)).Take(6));
        }
        public IOrderedQueryable GetVideoByUser(string name)
        {
            return (IOrderedQueryable)((from v in ctx.video
                                        where v.username == name
                                        orderby v.load_time descending
                                        select v));
        }

        public int GetVideoCount()
        { 
            return (from v in ctx.video
                        select v).Count();
        }

        public void DeleteVideoById(int id)
        {
            DataMode.video v = ctx.video.Single(c => c.video_id == id);
            ctx.video.DeleteOnSubmit(v);
            ctx.SubmitChanges();
        }
    }
}
